Thumb

What is IEnumerable?

1/12/2020 6:41:13 AM

IEnumerable  is an interface it’s have one method name as GetEnumerator. This method returns IEnumerable interface. This IEnumerable allow only read only accessor access the collection and use the for-each. This contains the System.Collections.Generic namespace and it is generic interface which allows looping over generic or non-generic lists. Now Given bellow the code and explain the code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using testForClass1;

namespace testFor
{
    public class Customer : IEnumerable
    {
        public IEnumerator GetEnumerator()
        {
            throw new NotImplementedException();
        }
    }
    public class Program 
    {
        static void Main(string[] args)
        {
           
            Console.Read();
        }
    }
}

Now we can see the IEnumerable inherited method contain the GetEnumerator method.